define([
        'app/utils/WebUtils',
        'app/utils/WeixinUtils',
        'text!app/tpl/orgVisit.html',
        "app/service/OrganizationService"
        ], function (
        WebUtils,
        WeixinUtils,
        orgVisitTpl,
        OrganizationService
    ) {

    

    var controller = function (orgUuid) {
    	
    	//0. Weixin Disabled
        WeixinUtils.disableAll();
        
        //1. Data Initialized
    	OrganizationService.getOrganizationDetails(orgUuid,function(resp){

            if($.isNull(resp)){
                $.redirectTo($.wjtBaseBackend + "/mvc/authorize?state=login");
                return;
            }

            if(resp.status!="200"){
                $.redirectTo($.wjtBaseBackend + "/mvc/authorize?state=login");
                return;
            }

            console.log(resp);

            //2. Weixin Initialized
            WeixinUtils.disableAll();


            //3. tpl Initialized - Never change!!!
            var tpl = WebUtils.tplInitialized();

            
            //4. UI Initialized
            var orgVisitUI = _.template(orgVisitTpl)({
                "attends":resp.result.attends,
                "logourl": resp.result.logourl,
                "name": resp.result.name,
                "uuid": resp.result.uuid,
                "rooms": resp.result.rooms,
                "unionid": $.getHashUrlParam("unionid")
            });

            //4. Assemble & Render
            tpl.append(orgVisitUI)

            //5. Render - Never change!!!
            WebUtils.render(tpl);
     
            //6. Directive initialized;
//            ManageOrganizationDirective.directive_redirectToCreateRoom();
                    
        });

        

        //7. routechange
        controller.onRouteChange = WebUtils.routeChange;

    };

    return controller;


});
